home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 52
/
Volume 52 - JOGO DISK .iso
/
Games
/
skipandgouls.swf
/
scripts
/
__Packages
/
sarbakan
/
input
/
KeyBasher.as
next >
Wrap
Text File
|
2007-10-01
|
2KB
|
64 lines
class sarbakan.input.KeyBasher
{
function KeyBasher(l_nKey, l_nPressNeeded, l_nUpdateDelay, l_fListener)
{
mx.transitions.OnEnterFrameBeacon.init();
this.oEnterFrameListener = new Object();
this.oEnterFrameListener.onEnterFrame = mx.utils.Delegate.create(this,this.update);
MovieClip.addListener(this.oEnterFrameListener);
this.oKey = sarbakan.input.KeyManager.getInstance();
this.oKey.addKeyListener(l_nKey,"KEY");
this.nPressNeeded = l_nPressNeeded;
this.nPressCount = 0;
this.nUpdateDelay = l_nUpdateDelay;
this.nUpdateCount = 0;
this.fListener = l_fListener;
this.bLastFrameWasDown = false;
this.bAutoBashing = false;
}
function enableAutoBashing()
{
this.bAutoBashing = true;
}
function disableAutoBashing()
{
this.bAutoBashing = false;
}
function end()
{
MovieClip.removeListener(this.oEnterFrameListener);
}
function update()
{
if(this.oKey.KEY)
{
if(!this.bLastFrameWasDown)
{
this.nPressCount = this.nPressCount + 1;
}
this.bLastFrameWasDown = true;
}
else
{
this.bLastFrameWasDown = false;
}
if(++this.nUpdateCount == this.nUpdateDelay)
{
this.report();
this.nUpdateCount = 0;
this.nPressCount = 0;
}
}
function report()
{
if(this.nPressCount >= this.nPressNeeded || this.bAutoBashing)
{
this.fListener(true);
}
else
{
this.fListener(false);
}
}
}